﻿/*   
    Copyright (C) 2009 Galaktika Corporation ZAO

    This file is a part of Galaktika.BusinessMonitor
 
    Galaktika.BusinessMonitor is a free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
      
    You should have received a copy of the GNU General Public License
    along with Galaktika.BusinessMonitor.  If not, see <http://www.gnu.org/licenses/>.
  
    If GPL v.3 is not suitable for your products or company,
    Galaktika Corp provides Galaktika.BusinessMonitor under a flexible commercial license
    designed to meet your specific usage and distribution requirements.
    If you have already obtained a commercial license from Galaktika Corp,
    you can use this file under those license terms.
*/

using System;
using System.Collections.Generic;
using Galaktika.BI.Silverlight.Services;
using Galaktika.BI.Runtime.Services;
using Ranet.Olap.Core.Metadata;
using Galaktika.BI.Silverlight.Commands;

namespace Galaktika.BI.Silverlight.ClientApp.Web.Runtime.DataAccess
{
    public class OlapMetadataManager
    {
        public string ConnectionString { get; private set; }
        public InvokeSchema Schema { get; private set; }

        public OlapMetadataManager(string connectionString, InvokeSchema schema)
        {
            this.ConnectionString = connectionString;
            this.Schema = schema;
        }

        public InvokeResultSchema GetCubeMetadata(
            //string cubeName, 
            //MetadataQueryType queryType
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, queryType.ToString()));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetLevels(
            //string cubeName, 
            //string dimensionUniqueName, 
            //string hierarchyUniqueName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.DimensionUniqueName, dimensionUniqueName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.HierarchyUniqueName, hierarchyUniqueName));

            using (var srv = new SyncDataService())
            {
                //var res = srv.InvokeCommand(schema);
                //List<InvokeArg> levels = XmlUtility.XmlStr2Obj<List<InvokeArg>>(res.Content);

                //var dict = new Dictionary<string, LevelInfo>();
                //levels.ForEach(a => dict.Add(a.Name, XmlUtility.XmlStr2Obj<LevelInfo>(a.Value)));

                //return dict;
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetLevelProperties(
            //string cubeName,
            //string dimensionUniqueName,
            //string hierarchyUniqueName,
            //string levelUniqueName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.DimensionUniqueName, dimensionUniqueName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.HierarchyUniqueName, hierarchyUniqueName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.LevelUniqueName, levelUniqueName));

            using (var srv = new SyncDataService())
            {
                //var res = srv.InvokeCommand(schema);
                //List<InvokeArg> levels = XmlUtility.XmlStr2Obj<List<InvokeArg>>(res.Content);

                //var dict = new Dictionary<string, LevelPropertyInfo>();
                //levels.ForEach(a => dict.Add(a.Name, XmlUtility.XmlStr2Obj<LevelPropertyInfo>(a.Value)));

                //return dict;
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetMeasures(
            //string cubeName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetMeasure(
            //string cubeName, string measureUniqueName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MeasureUniqueName, measureUniqueName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetKPIs(
            //string cubeName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetKPI(
            //string cubeName, 
            //string kpiUniqueName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.KpiUniqueName, kpiUniqueName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetLevel(
            //string cubeName, 
            //string dimensionUniqueName, 
            //string hierarchyUniqueName, 
            //string levelUniqueName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.DimensionUniqueName, dimensionUniqueName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.HierarchyUniqueName, hierarchyUniqueName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.LevelUniqueName, levelUniqueName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetDimensions(
            //string cubeName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }

        public InvokeResultSchema GetHierarchies(
            //string cubeName, 
            //string dimensionUniqueName
            )
        {
            //var schema = new InvokeSchema(CommandId.GetMetadataCommandId);
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.MetadataQueryInfo, this.Args));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.CubeName, cubeName));
            //schema.Args.Add(new InvokeArg(KnownInvokeArgs.DimensionUniqueName, dimensionUniqueName));

            using (var srv = new SyncDataService())
            {
                return srv.InvokeCommand(this.Schema);
            }
        }
    }
}
